home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
game
/
board
/
Crafty-15.19.lha
/
crafty-15.19
/
src
/
init.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-26
|
51KB
|
1,605 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "chess.h"
#include "data.h"
#if defined(UNIX) || defined(AMIGA)
# include <unistd.h>
#endif
#include "epdglue.h"
#if defined(NT_i386) || defined(NT_AXP)
# include <fcntl.h> /* needed for definition of "_O_BINARY" */
#endif
#if defined(AMIGA)
#include <proto/exec.h>
#include <exec/memory.h>
static unsigned long largest_chunk ;
#endif
#if defined(COMPACT_ATTACKS)
extern unsigned char init_l90[];
extern unsigned char init_l45[];
extern unsigned char init_r45[];
#else
int init_r90[64] = { 56, 48, 40, 32, 24, 16, 8, 0,
57, 49, 41, 33, 25, 17, 9, 1,
58, 50, 42, 34, 26, 18, 10, 2,
59, 51, 43, 35, 27, 19, 11, 3,
60, 52, 44, 36, 28, 20, 12, 4,
61, 53, 45, 37, 29, 21, 13, 5,
62, 54, 46, 38, 30, 22, 14, 6,
63, 55, 47, 39, 31, 23, 15, 7 };
int init_l90[64] = { 7, 15, 23, 31, 39, 47, 55, 63,
6, 14, 22, 30, 38, 46, 54, 62,
5, 13, 21, 29, 37, 45, 53, 61,
4, 12, 20, 28, 36, 44, 52, 60,
3, 11, 19, 27, 35, 43, 51, 59,
2, 10, 18, 26, 34, 42, 50, 58,
1, 9, 17, 25, 33, 41, 49, 57,
0, 8, 16, 24, 32, 40, 48, 56 };
int init_l45[64] = { 0,
2, 5,
9, 14, 20,
27, 35, 1, 4,
8, 13, 19, 26, 34,
42, 3, 7, 12, 18, 25,
33, 41, 48, 6, 11, 17, 24,
32, 40, 47, 53, 10, 16, 23, 31,
39, 46, 52, 57, 15, 22, 30,
38, 45, 51, 56, 60, 21,
29, 37, 44, 50, 55,
59, 62, 28, 36,
43, 49, 54,
58, 61,
63 };
int init_ul45[64] = { 0,
8, 1,
16, 9, 2,
24, 17, 10, 3,
32, 25, 18, 11, 4,
40, 33, 26, 19, 12, 5,
48, 41, 34, 27, 20, 13, 6,
56, 49, 42, 35, 28, 21, 14, 7,
57, 50, 43, 36, 29, 22, 15,
58, 51, 44, 37, 30, 23,
59, 52, 45, 38, 31,
60, 53, 46, 39,
61, 54, 47,
62, 55,
63 };
int init_r45[64] = { 28,
21, 15,
10, 6, 3,
1, 0, 36, 29,
22, 16, 11, 7, 4,
2, 43, 37, 30, 23, 17,
12, 8, 5, 49, 44, 38, 31,
24, 18, 13, 9, 54, 50, 45, 39,
32, 25, 19, 14, 58, 55, 51,
46, 40, 33, 26, 20, 61,
59, 56, 52, 47, 41,
34, 27, 63, 62,
60, 57, 53,
48, 42,
35 };
int init_ur45[64] = { 7,
6, 15,
5, 14, 23,
4, 13, 22, 31,
3, 12, 21, 30, 39,
2, 11, 20, 29, 38, 47,
1, 10, 19, 28, 37, 46, 55,
0, 9, 18, 27, 36, 45, 54, 63,
8, 17, 26, 35, 44, 53, 62,
16, 25, 34, 43, 52, 61,
24, 33, 42, 51, 60,
32, 41, 50, 59,
40, 49, 58,
48, 57,
56 };
int diagonal_length[64] = { 1,
2, 2,
3, 3, 3,
4, 4, 4, 4,
5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7,
6, 6, 6, 6, 6, 6,
5, 5, 5, 5, 5,
4, 4, 4, 4,
3, 3, 3,
2, 2,
1 };
#endif
void Initialize(int continuing) {
/*
----------------------------------------------------------
| |
| perform routine initialization. |
| |
----------------------------------------------------------
*/
int i, j, major, minor;
TREE *tree;
#if defined(SMP)
for (i=1;i<MAX_BLOCKS+1;i++) {
local[i]=(TREE*) malloc(sizeof(TREE));
local[i]->used=0;
}
local[0]->parent=(TREE*)-1;
#endif
tree=local[0];
i=0;
InitializeZeroMasks();
#if defined(SMP)
InitializeSMP();
#endif
InitializeMasks();
InitializeRandomHash();
InitializeAttackBoards();
InitializePawnMasks();
InitializePieceMasks();
InitializeChessBoard(&tree->position[0]);
#if defined(NT_i386) || defined(NT_AXP)
_fmode = _O_BINARY; /* set global file mode to binary to avoid text translation */
#endif
EGInit();
tree->last[0]=tree->move_list;
#if defined(MACOS)
sprintf(log_filename,":%s:book.bin",book_path);
#else
sprintf(log_filename,"%s/book.bin",book_path);
#endif
book_file=fopen(log_filename,"rb+");
if (!book_file) {
book_file=fopen(log_filename,"rb");
if (!book_file) {
#if defined(MACOS)
printf("unable to open book file [:%s:book.bin].\n",book_path);
#else
printf("unable to open book file [%s/book.bin].\n",book_path);
#endif
printf("book is disabled\n");
}
else {
#if defined(MACOS)
printf("unable to open book file [:%s:book.bin] for \"write\".\n",book_path);
#else
printf("unable to open book file [%s/book.bin] for \"write\".\n",book_path);
#endif
printf("learning is disabled\n");
}
}
#if defined(MACOS)
sprintf(log_filename,":%s:books.bin",book_path);
#else
sprintf(log_filename,"%s/books.bin",book_path);
#endif
books_file=fopen(log_filename,"rb");
#if defined(MACOS)
if (!books_file) printf("unable to open book file [:%s:books.bin].\n",book_path);
#else
if (!books_file) printf("unable to open book file [%s/books.bin].\n",book_path);
#endif
if (book_file) {
fseek(book_file,-sizeof(int),SEEK_END);
fread(&major,sizeof(int),1,book_file);
minor=major&65535;
major=major>>16;
if (major<15 || (major==15 && minor<15)) {
Print(4095,"\nERROR! book.bin not made by version 15.15 or later\n");
book_file=0;
books_file=0;
}
}
#if defined(MACOS)
sprintf(log_filename,":%s:book.lrn",book_path);
#else
sprintf(log_filename,"%s/book.lrn",book_path);
#endif
book_lrn_file=fopen(log_filename,"a");
if (!book_lrn_file) {
#if defined(MACOS)
printf("unable to open book learning file [:%s:book.lrn].\n",book_path);
#else
printf("unable to open book learning file [%s/book.lrn].\n",book_path);
#endif
printf("learning disabled.\n");
learning&=~(book_learning+result_learning);
}
if (learning&position_learning) {
#if defined(MACOS)
sprintf(log_filename,":%s:position.bin",book_path);
#else
sprintf(log_filename,"%s/position.bin",book_path);
#endif
position_file=fopen(log_filename,"rb+");
if (position_file) {
fseek(position_file,0,SEEK_END);
if (ftell(position_file) == 0) {
fclose(position_file);
position_file=0;
}
}
if (!position_file) {
position_file=fopen(log_filename,"wb+");
if (positio